package JavaSE.CODE.javaIO;

import java.io.FileInputStream;

/**
 * 文件字节输入流
 */

public class FileInputStreamDemo {

    public static void main(String[] args) throws Exception{
        FileInputStream fis = new FileInputStream("D:\\fileTest.txt");
        //单字节读入
        /*
        int data=0;
        while((data=fis.read())!=-1) {
            System.out.println((char) data);
        }
        System.out.println("over");
        */

        //每次读入缓冲区大小
        /*
        byte[] nums = new byte[3];
        fis.read(nums);
        System.out.println(new String(nums));
        fis.read(nums);
        System.out.println(new String(nums));
        fis.read(nums);
        System.out.println(new String(nums,0,1));
        */

        //优化
        byte[] buf = new byte[1024];
        int count = 0;
        while((count=fis.read(buf))!=-1){
            System.out.println(new String(buf, 0, count));
            //count是实际读出来的数字个数
        }
        fis.close();
    }

}
